package view.table.square;

import java.util.List;

import model.Square;
import view.table.CellValueChangeEvent;
import view.table.ExtendedAbstractTableModel;

public class SquareTableModel extends ExtendedAbstractTableModel {

	private static final long serialVersionUID = -491471296248705862L;
	private List<Square> squares;

	public SquareTableModel(List<Square> square) {
		super();
		this.squares = square;

	}

	@Override
	public int getRowCount() {
		return squares.size();
	}

	@Override
	public int getColumnCount() {
		return 3;
	}

	@Override
	public String getColumnName(int col) {
		switch (col) {
		case 0:
			return "x";
		case 1:
			return "y";
		case 2:
			return "a";
		default:
			return "undefined";
		}
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Square square = squares.get(rowIndex);
		switch (columnIndex) {
		case 0:
			return square.getX();
		case 1:
			return square.getY();
		case 2:
			return square.getA();
		default:
			return "undefined";
		}
	}

	@Override
	public Class<?> getColumnClass(int c) {
		return Integer.class;
	}

	@Override
	public boolean isCellEditable(int row, int col) {
		return true;
	}

	@Override
	public void setValueAt(Object value, int row, int col) {
		Square square = squares.get(row);
		fireChange(new CellValueChangeEvent(square, value, col));
	}

	public void addSquare(Square s) {
		squares.add(s);
	}

	public void removeSquare(Square s) {
		squares.remove(s);
	}

	public List<Square> getSquares() {
		return squares;
	}

	public void setSquares(List<Square> squares) {
		this.squares = squares;
	}
}
